/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.mleiria.plots;

import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import pt.mleiria.supervisedlearning.GradientDescent;
import pt.mleiria.utils.EnvSettings;

/**
 *
 * @author manuel
 */
public class LineChartSample extends Application {

    GradientDescent gd;

    @Override
    public void start(Stage stage) {
        loadData();
        stage.setTitle("Line Chart Sample");
        //defining the axes
        final NumberAxis xAxis = new NumberAxis();
        final NumberAxis yAxis = new NumberAxis();
        xAxis.setLabel("Number of Iterations");
        //creating the chart
        final LineChart<Number, Number> lineChart = new LineChart<Number, Number>(xAxis, yAxis);

        lineChart.setTitle("Cost Function");
        //defining a series
        XYChart.Series series = new XYChart.Series();
        series.setName("J");
        //populating the series with data
        int len = gd.getJ().length;
        for (int i = 0; i < len; i++) {
            series.getData().add(new XYChart.Data(i, gd.getJ()[i]));
        }
        Scene scene = new Scene(lineChart, 800, 600);
        lineChart.getData().add(series);
        lineChart.setCreateSymbols(false);
        stage.setScene(scene);
        stage.show();
    }

    private void loadData() {
        String ex1data2 = EnvSettings.EX1DATA2;
        gd = new GradientDescent(ex1data2, true, 3);
        gd.setMaximumIterations(1000);
        gd.evaluate();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
